package com.chat.service;

import com.chat.Local;
import com.chat.common.Group;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.common.User;
import com.chat.view.MemberData;
import javafx.application.Platform;

import java.util.ArrayList;
import java.util.Objects;

import static com.chat.view.GroupMemberController.member;

/*
  获取当前群的成员列表
 */
public class GetGroupMember {
       public void get(String groupid){
              Message msg=new Message();
              msg.setMesType(MessageType.MESSAGE_GET_GROUP_MEMBER);
              Group group=new Group();
              group.setId(groupid);
              msg.setData(group);
              ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
              clientConnectServerThread.send(msg);
       }
       public void set(ArrayList<User>a){
           Platform.runLater(new Runnable() {
                  @Override
                  public void run() {
                      for(int i=0;i<a.size();i++){
                          if(Objects.equals(a.get(i).getUsername(), Local.user.getUsername())){//记录自己在这个群聊中的地位
                              Local.state=a.get(i).getState();
                          }
                          System.out.println(a.get(i).getUsername()+" "+a.get(i).getNickname());
                          member.add(new MemberData(a.get(i).getNickname(),a.get(i).getUsername(),a.get(i).getState()));
                      }
                  }
            });

       }
}
